//
//  YDUserInfoTableViewCell.m
//  IngCard
//
//  Created by kf on 2017/8/9.
//  Copyright © 2017年 IngDan. All rights reserved.
//

#import "YDUserInfoTableViewCell.h"


@implementation  YDUserInfoCellDataSource
-(Class) viewClass
{
    return [YDUserInfoTableViewCell class];
}

@end

@interface YDUserInfoTableViewCell()
@property(nonatomic, strong) UILabel *nameLabel;
@property(nonatomic, strong) UILabel *titleLabel;
@property(nonatomic, strong) UILabel *originationLabel;

@property(nonatomic, strong) UIButton *guideButton;
@end
@implementation YDUserInfoTableViewCell

+(CGFloat)viewHeight:(YDUserInfoCellDataSource *) dataSource
{
    return dataSource.height ?: 226;
}

-(void) initSubviews
{
    [super initSubviews];
    
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(69);
        make.left.equalTo(36);
        make.width.equalTo(self.contentView);
    }];
    
    [self.contentView addSubview:self.guideButton];
    [self.guideButton makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(40);
        make.right.equalTo(self.contentView).offset(-30);
    }];
    
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_left);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(8);
        make.width.equalTo(self.contentView);
    }];
    
    [self.contentView addSubview:self.originationLabel];
    [self.originationLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(7);
        make.width.equalTo(self.contentView);
    }];
}

-(void) onViewModelChanged
{
    YDUserInfoCellDataSource *dataSource = (YDUserInfoCellDataSource *)self.dataSource;
    if (dataSource)
    {
        self.nameLabel.text = dataSource.name;
        self.titleLabel.text = dataSource.title;
        self.originationLabel.text = dataSource.origination;
    }
}


#pragma mark - private
- (void)guideButtonAction:(UIButton *)btn
{
    YDUserInfoCellDataSource *dataSource = (YDUserInfoCellDataSource *)self.dataSource;
    if (dataSource && dataSource.editBlock)
    {
        BlockGoGo(dataSource.editBlock);
    }
}

#pragma mark - lazy loading
- (UILabel *) nameLabel
{
    if (!_nameLabel)
    {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.text = @"姓名";
        _nameLabel.textAlignment = NSTextAlignmentLeft;
        _nameLabel.font = UIFontBoldMake(32);
        _nameLabel.textColor = UIColorMake(44, 44, 44);
    }
    return _nameLabel;
}

- (UILabel *) titleLabel
{
    if (!_titleLabel)
    {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.text = @"职位";
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.font = UIFontMake(18);
        _titleLabel.textColor = UIColorMake(44, 44, 44);
    }
    return _titleLabel;
}
- (UILabel *) originationLabel
{
    if (!_originationLabel)
    {
        _originationLabel = [[UILabel alloc] init];
        _originationLabel.text = @"公司";
        _originationLabel.textAlignment = NSTextAlignmentLeft;
        _originationLabel.font = UIFontBoldMake(18);
        _originationLabel.textColor = UIColorMake(44, 44, 44);
    }
    return _originationLabel;
}

-(UIButton *) guideButton
{
    if (!_guideButton)
    {
        _guideButton = [[UIButton alloc] init];
        [_guideButton setBackgroundImage:UIImageMake(@"userGuideButtonImage") forState:(UIControlStateNormal)];
        _guideButton.layer.masksToBounds = YES;
        [_guideButton addTarget:self
                        action:@selector(guideButtonAction:)
              forControlEvents:UIControlEventTouchUpInside];
        [_guideButton sizeToFit];
    }
    return _guideButton;
}

@end

